package com.yh.homestay.controller;

import com.yh.homestay.common.SysRoleEditResult;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.SysRole;
import com.yh.homestay.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    @RequestMapping(value = "/SysRole-list" ,produces = "application/json; charset=utf-8")
    @ResponseBody
    public HomeStayResult selectAll(String roleName, Integer page, Integer limit){
        HomeStayResult homeStayResult = sysRoleService.selectAll(roleName ,page ,limit);
        return homeStayResult;
    }

    @RequestMapping("/SysRole-add")
    public HomeStayResult addSysRole(SysRole sysRole){
        int Role = sysRoleService.addSysRole(sysRole);
        if(Role>0){
            return HomeStayResult.ok();
        }else{
            return HomeStayResult.build(500,"系统正忙,请稍后添加!");
        }
    }

    @RequestMapping("/SysRole-edit/{id}")
    @ResponseBody
    public HomeStayResult editSysRole(@PathVariable Integer id, String roleName, String roleDesc){
        HomeStayResult update = sysRoleService.update(id,roleName,roleDesc);
        return update;
    }

    @RequestMapping("/SysRole-delete/{id}")
    @ResponseBody
    public HomeStayResult deleteById(@PathVariable Integer id){
        HomeStayResult delete = sysRoleService.delete(id);
        return delete;
    }

    @RequestMapping("/SysRole-edit/selectOne/{id}")
    @ResponseBody
    public SysRoleEditResult editSysRole(@PathVariable Integer id){
        SysRoleEditResult sysRoleEditResult = sysRoleService.selectOne(id);
        return sysRoleEditResult;
    }
    @RequestMapping("/SysRole-deleteAll")
    @ResponseBody
    public HomeStayResult delectAll(@RequestParam List<Integer> ids){
        HomeStayResult actionResult = sysRoleService.delectAll(ids);
        return actionResult;
    }
}
